package com.eric.controller;
import cn.dev33.satoken.stp.StpUtil;
import cn.dev33.satoken.util.SaResult;
import cn.hutool.http.server.HttpServerRequest;
import com.eric.domain.dto.SysUserDto;
import com.eric.service.UserLoginService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import java.util.Map;

@RestController
@RequiredArgsConstructor
@RequestMapping("/login")
public class LoginController {

    private final UserLoginService userLoginService;

    @PostMapping("/saveOne")
    public SaResult saveOneUser(@RequestBody SysUserDto sysUserDto, HttpServerRequest request){
        return userLoginService.saveOneUser(sysUserDto,request);
    }
    @PostMapping("/")
    public SaResult loginByPw(@RequestBody Map<String,String> loginObj){
        return userLoginService.loginByPw(loginObj);
    }

    @GetMapping("/logout")
    public SaResult logout(){
        StpUtil.logout();
        return SaResult.ok();
    }
}
